<?php
	include_once("db/UserDAO.inc");
	include_once("db/AuditLogs.inc");
	
	$username = $_REQUEST["username"];
	$password = $_REQUEST["password"];
	
	if (User::authenticateUser($username, $password)) {
		$_SESSION["userValid"] = true;
		
		$user = User::getUserByName($username);
		
		$_SESSION["accessLevel"] = $user->accessLevel;
		$_SESSION["uid"] = $user->uid;
		AuditLogs::insertLog($username, 'admin - login', 'success');
		
		header("Location: .");
	} else {
		AuditLogs::insertLog($username, 'admin - login', 'failure');
		header("Location: .?error=invalidUser");
	}
?>